<html><head><title>Gosub : Return</title></head>
<body bgcolor="#FFFFDF" link="#009999" vlink="#006666" alink="#006666">
<font face="Arial" size="2"><p align="center"><b><font size="5">Gosub : Return</font></b></p>

<br><b>Syntax</b><blockquote><pre><font face="Courier New, Courier, mono"size="2"><b><font color="#006666">Gosub</font></b> MyLabel 
   
MyLabel: 
  ...
<b><font color="#006666">Return</font></b>

</font></pre></blockquote>
<b>Description</b><br><blockquote>


<b><font color="#006666">Gosub</font></b> stands for 'Go to sub routine'. A <a href="../reference/general_rules.html">label</a> must be specified after <b><font color="#006666">Gosub</font></b>, at that point 
the program execution continues immediately after the position defined by that label, and will do so until 
encountering a <b><font color="#006666">Return</font></b>. When a return is reached, the program execution is then transferred immediately 
below the <b><font color="#006666">Gosub</font></b>. 
<br>
<b><font color="#006666">Gosub</font></b> is useful when building fast structured code. 
<br>
<br>
Another technique which may be used in order to insert a sub routine into a standalone program component 
is to use <a href="../reference/procedures.html">procedures</a>. 
<b><font color="#006666">Gosub</font></b> may only be used within the main body of the source code, and may not be used within 
<a href="../reference/procedures.html">procedures</a>. 

</blockquote><p><b>Example</b></p><blockquote>


<pre><font face="Courier New, Courier, mono"size="2">  a = 1
  b = 2
  <b><font color="#006666">Gosub</font></b> ComplexOperation 
  <b><font color="#006666">Debug</font></b> a 
  <b><font color="#006666">End</font></b> 
       
  ComplexOperation: 
    a = b*2+a*3+(a+b) 
    a = a+a*a 
  <b><font color="#006666">Return</font></b> 
</font></pre>

</blockquote>
<br><b>Syntax</b><blockquote><pre><font face="Courier New, Courier, mono"size="2"><b><font color="#006666">FakeReturn</font></b> 
</font></pre></blockquote>
<b>Description</b><br><blockquote>


If the command <a href="../reference/others.html">Goto</a> is used within the body of a sub routine, <b><font color="#006666">FakeReturn</font></b> must be used. 
<b><font color="#006666">FakeReturn</font></b> simulates a return without actually executing a return, and if it is not used, the program will crash. 
Note: To exit a loop safely, <a href="../reference/break_continue.html">Break</a> should be used instead of Goto. 

</blockquote><p><b>Example</b></p><blockquote>


<pre><font face="Courier New, Courier, mono"size="2">  <b><font color="#006666">Gosub</font></b> SubRoutine1
     
  SubRoutine1:
    ...
    <b><font color="#006666">If</font></b> a = 10
      <b><font color="#006666">FakeReturn</font></b> 
      <b><font color="#006666">Goto</font></b> Main_Loop 
    <b><font color="#006666">EndIf</font></b> 
  <b><font color="#006666">Return</font></b>
</font></pre>
</body></html>